<?php

/*
  Project     : 48c6c450f1a4a0cc53d9585dc0fee742
  Created on  : Mar 16, 2013, 11:29:15 PM
  Author      : Truong Khuong - khuongxuantruong@gmail.com
  Description :
  Purpose of the stylesheet follows.
 */

class setting_model extends backend_model {
    function __construct()
    {
        parent::__construct('config','conf');
    }
    function get($_id){
        $query=$this->db
                ->where("conf_id",$_id)
                ->get("config");
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return null;
        }
        $rs = $query->result();
        if(isset($rs[0]))   {
            return $rs[0];
        }
        return null;
    }
    function gets(){
        $query=$this->db
                ->get('config');
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return null;
        }
        $rs = $query->result();
        return $rs;
    }
    function insert_onduplicate_update_apri($aParamsi,$aUpdate){
        $this->db->on_duplicate_update('config', $aUpdate, $aParamsi); 
        $count = $this->db->affected_rows();
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        if($count>0) return true;
        return false;
    }
    function insert($params){
        //$this->db->set('_insert', 'NOW()', FALSE);
        @$this->db->insert("config", $params); 
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        @$count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    
    function update($ID,$params){
        //$this->db->set('_update', 'NOW()', FALSE);
        $this->db->where('conf_id', $ID);
        @$this->db->update("config", $params); 
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        @$count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function binding($type=null){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `config`.*,`config`.`conf_id` as '_id'
            FROM `config`
            ";
        $config=array(
            "strQuery"=>$strQuery,
            "usingLimit"=>true,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function colmod(){
        return array(
            array(  
                "text"          =>"#"            
                ,"datafield"    =>"_id" 
                ,"cellsalign"   =>"right"
                ,"width"        => 80 
                //,"hidden"       =>true
                ),
            array(  
                "text"          =>"ID"            
                ,"datafield"    =>"conf_id" 
                ,"cellsalign"   =>"right"
                ,"width"        => 80 
                //,"hidden"       =>true
                ),
            array(  
                "text"          =>"Name"            
                ,"datafield"    =>"conf_name" 
                ,"width"        => 220
                ,"editable"     =>true
                ),
             array(  
                "text"          =>"Key"            
                ,"datafield"    =>"conf_key" 
                ,"width"        => 120
                ,"editable"     =>true
                ),
            array(  
                "text"          =>"Value"            
                ,"datafield"    =>"conf_value" 
                ,"width"        => 120
                ,"editable"     =>true
                //,"hidden"       =>true
                ),
            array(  
                "text"          =>"Desc"            
                ,"datafield"    =>"conf_desc" 
                //,"width"        => 220
                ,"editable"     =>false
                ),
            
        );
    }
}

?>
